#include"SqQueue.h"
#define ElemType int
#define MaxSize 10
// isEmpty?
bool QueueEmpty(SqQueue Q) {
    if (Q.front == Q.rear) {
        return true;
    }

    return false;
}

// isFull?
bool QueueFull(SqQueue Q) {
    return ((Q.rear + 1) % MaxSize == Q.front);
}

// Init
bool InitSqQueue(SqQueue& Q) {
    if (!QueueEmpty(Q)) {
        return false;
    }

    Q.front = Q.rear = 0;
    return true;
}


// EnQueue
bool EnQueue(SqQueue& Q, ElemType x) {
    if (QueueFull(Q)) {
        return false;
    }

    Q.data[Q.rear] = x;
    Q.rear = (Q.rear + 1) % MaxSize;
    return true;
}

// DeQueue
bool DeQueue(SqQueue& Q, ElemType& x) {
    if (QueueEmpty(Q)) {
        return false;
    }

    x = Q.data[Q.front];
    Q.front = (Q.front + 1) % MaxSize;
    return true;
}

// GetHead
bool GetHead(SqQueue Q, ElemType& x) {
    if (QueueEmpty(Q)) {
        return false;
    }

    x = Q.data[Q.front];
    return true;
}

// GetLength

int GetLength(SqQueue Q) {
    return (Q.rear + MaxSize - Q.front) % MaxSize;
}